﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NhanAi.DAO;
using NhanAi.Entity;
using Home.Utils;
using NhanAi.App_Code;
namespace NhanAi.Admin
{
    public partial class ListContacts : ListPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Authenticate();
            SubscribingDao dao = new SubscribingDao();
            string searchString = Request["searchString"] == null ? "" : Request["searchString"];
            pageNum = TypeWrapper.GetInt32(Request["page"]);
            int parent = TypeWrapper.GetInt32(Request["parent"]);
            if (pageNum == 0) pageNum = 1;
            int total = 0;
            if (Request.HttpMethod == "POST")
            {
                string ids = Request["ids"];
                if (!String.IsNullOrEmpty(ids))
                {
                    dao.Delete(ids);
                    SetMessage("Xóa thành công", "");
                }
            }
            List<Subscribing> list;

            list = dao.ReadMany(PAGE_SIZE, pageNum, out total);

            rptTaxonomy.DataSource = list;
            rptTaxonomy.DataBind();
            paging.TotalItemCount = total;
            paging.PageNumber = pageNum;
            paging.PageSize = PAGE_SIZE;
            paging.SearchString = searchString;
            SetCurrentPage("Contact");
        }

        protected void btnUpdateMenu_Click(object sender, EventArgs e)
        {
            TaxonomyDao daoTax = new TaxonomyDao();
            string[] keys = { "tin-tuc", "y-li", "dong-duoc", "cham-cuu", "phuong-te", "benh-hoc", "dieu-tri", "tai-lieu", "lop-hoc" };
            List<object[]> list = new List<object[]>();
            foreach (string k in keys)
            {
                Taxonomy parent = daoTax.Read(k, NAConstants.ALL_LANGUAGE);
                if (parent != null)
                {
                    List<Taxonomy> childrens = daoTax.ReadAll(parent.Id);
                    object[] item = new object[] { k, parent, childrens };
                    list.Add(item);
                }
            }
            Application["submenu"] = list;
        }
    }
}